#include <stdio.h>
#include <string.h>

void exchange1(char *s, int len)
{
    for(int i = 0; i < len / 2; i++)
    {
        char temp = s[i];
        s[i] = s[len-i-1];
        s[len-i-1] = temp;
    }
}

void exchange2(char *s)
{
    int len = 0;
    for(int i = 0; i < strlen(s); i++)
    {
        if(s[i] == ' ' || s[i] == '\0')
        {
            exchange1(s+i-len,len);
            len = 0;
        }
        else{
            len++;
        }
    }
}

int main()
{
    char s[] = "i am from nanjing";
    exchange1(s,strlen(s));
    printf("%s\n",s);
    exchange2(s);
    printf("%s\n",s);
    return 0;

}